AJAX Based Programmatic String Checking (RapidSpellCheckerClient)

The RapidSpellCheckerClient control can be used to programmatically check strings, in Javascript. If the control has been added to the page it will emit the required Javascript to setup an instance for use.

Code Example: Obtaining An Instance

//Perform this anytime AFTER the page has loaded
var rsc = <%= RapidSpellCheckerClient1.ClientSideObject %>;

where RapidSpellCheckerClient1 is the Control ID.

Code Example: Asynchronously Spell Checking A String

Generally we recommend that spell checking be performed asynchronously, as this allows the UI to respond to user events. Asynchronous functions are non blocking, so the return is handled by a callback function. Using asynchronous functions can be awkward, so we also provide a synchronous version, below. This asynchronous method is available in browsers that support XmlHttpRequst (eg. IE, FF...) and also in older browsers which don't (eg Opera 6).

rsc.Check(textToCheck, display);

Display is the name of a function that will handle the call back and process the result. See below.

Code Example: Synchronously Spell Checking A String

This form is used to run the spell check synchronously. This will cause the UI to block while the browser waits for the response. Under good network conditions this should be acceptable. One warning about this synchronous method is that it is only available in browsers capable of XmlHttpRequest (AJAX calls). If the browser cannot process these then the asynchronous method should be used instead.

var result = rsc.Check(textToCheck);

Code Example: Processing The Result

The result is an object with the following properties.

originalText //The text that was spell checker
numberOfErrors //The number of spelling errors
errorPositionArray //An array of errors, with their positions and suggestions

errorPositionArray[n].start //Where the spelling error is in the original text
errorPositionArray[n].end //Where the spelling error ends
errorPositionArray[n].suggestions //Simple array of string suggestions

The result object, which is returned by Check in synchronous calls, or passed to the call-back function in asynchronous calls, can then be processed.

function display(result){
    var resultTB = document.getElementById("resultTB");

    resultTB.value = '"' + result.originalText + "\" has " + result.numberOfErrors + " errors\r\n\r\n";
    for(var e = 0; e<result.errorPositionArray.length; e++){
        resultTB.value += "Error "+e+": " + result.errorPositionArray[e].word + "\r\n";
        resultTB.value += "\tstart:"+result.errorPositionArray[e].start+"\r\n";
        resultTB.value += "\tend:"+result.errorPositionArray[e].end+"\r\n";
        resultTB.value += "\tsuggestions: " + (result.errorPositionArray[e].suggestions.length==0?"none":"") + "\r\n";
        for(var s = 0; s<result.errorPositionArray[e].suggestions.length; s++){
            resultTB.value += "\t\t" + result.errorPositionArray[e].suggestions[s] + "\r\n";
        }
        resultTB.value += "\r\n";
    }
}

Code Example: Add Word To User Dictionary

Adding to the user dictionary is always asynchronous and requires the UserDictionaryFile property to be set to a file path on the server where the dictionary will be stored.

rsc.AddWord(wordToAdd);

Code Example: Setting Properties

Spell check options can be set on the server through the Control properties or on the client side through the Javascript functions.

rsc.setParameterValue(optionName, value);

where optionName is the name as specified exactly in the Control serverside properties. Similarly property values can be obtained through

rsc.getParameterValue(optionName);

Please consult the product demos for a complete example, plus how to access parameter names programmatically.